class Solution(object):
    def maxNonOverlapping(self, nums, target):
        prefix = {0}
        ans = 0
        now = 0
        for num in nums:
            if now + num - target in prefix:
                ans += 1
                prefix = {0}
                now = 0
            else:
                now += num
                prefix.add(now)
        return ans
